package actions;

import javax.ejb.EJB;
import java.util.*;

import entities.*;

import javax.ejb.Local;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import utils.*;
import beans.*;

public class ShowBorrowedAction extends ActionSupport {

	private static final long serialVersionUID = 4L;
	private ArrayList<Item> recentBorrowed;
	@EJB
	private SearchManager searchMan = new SearchBean();

	public String execute() {
		Object userIdObj = ActionContext.getContext().getSession()
				.get("userId");
		if (userIdObj == null) {
			// take the user to the login page
			this.addActionError("You must login to view this page");
			return ERROR;
		}

		int userId = ((Integer) userIdObj).intValue();

		recentBorrowed = searchMan.getItems(userId, Item.loaned, null, 5000);
		return SUCCESS;
	}

	public ArrayList<Item> getRecentBorrowed() {
		return recentBorrowed;
	}

	public void setRecentBorrowed(ArrayList<Item> recentBorrowed) {
		this.recentBorrowed = recentBorrowed;
	}

}